package byggeTegningGUI;

import context.*;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JPanel;

import drawing2D.Drawing2D;





// ***************************************************************************
// *** CLASS: JDrawPanel
// ***************************************************************************
public class JDrawPanel extends JPanel implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final long serialVersionUID=0; // TODO ?
  private Drawing2D model2D;


  // *************************************************************************
  // *** CONSTRUCTOR: JDrawPanel
  // *************************************************************************
  public JDrawPanel(Drawing2D model2D)
  { this.model2D=model2D;
    this.addComponentListener(componentListener);
    this.setBackground(Color.white);
  }

  // *************************************************************************
  // *** METHOD: paint
  // *************************************************************************
  /**
  * This method is called to repaint this JComponent.
  * @param g the graphics context.
  **/
  public void paint(Graphics g)
  {
    update(g);
  }

  // *************************************************************************
  // *** METHOD: update
  // *************************************************************************
  /**
  * Updates this component.
  * @param g the specified context to use for updating.
  **/
  public void update(Graphics g)
  { Color color=g.getColor();
    g.setColor(Color.white);
    g.fillRect(0,0,4000,4000);
    g.setColor(color);
//    model2D.setDefault2DScaling();
    model2D.paint(g);
  }



  // ***************************************************************************
  // *** ComponentListener: Methods
  // ***************************************************************************
  private ComponentListener componentListener=new ComponentListener()
  {
    //** Invoked when the component's size changes. **/
    public void componentResized(ComponentEvent e) { }

    //** Invoked when the component's position changes. **/
    public void componentMoved(ComponentEvent e) {}

    //** Invoked when the component has been made visible. **/
    public void componentShown(ComponentEvent e) {}

    //** Invoked when the component has been made invisible. **/
    public void componentHidden(ComponentEvent e) {}

  };

}